import handleArr from "./index"


const reducer = (state = { ...handleArr.state }, action: { type: string, val: number }) => {
  const newState = JSON.parse(JSON.stringify(state))
  
  console.log(handleArr.actionNames, '///////////')
  for (let key in handleArr.actionNames) {
    // key是每一个键
    // 判断是不是相等
    // if(action.type==="add1")
    if (action.type === handleArr.actionNames[key]) {
      handleArr.actions[handleArr.actionNames[key]](newState, action)
      break;   // 结束本次循环
    }

  }

  return newState
}

export default reducer